#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>

int g_val=100;
int main()
{
  printf("father is running,pid:%d,ppid:%d\n",getpid(),getppid());
  pid_t id=fork();
  if(id==0)
  {
    int cnt=5;
    while(1)
    {
      printf("i am child process,pid:%d:ppid:%d,g_val:%d,&g_val:%p\n",getpid(),getppid(),g_val,&g_val);
      sleep(1);
      cnt--;
      if(cnt==0)
      {
        g_val=300;
        printf("i am child process,change %d -> %d\n",100,300);
      }
    }   
  }
  else
  {
    while(1)
    {
      printf("i am father process,pid:%d:ppid:%d,g_val:%d,&g_val:%p\n",getpid(),getppid(),g_val,&g_val);
      sleep(1);
    }
  }    
  return 0;
}
//int main(/*int argc,char*argv[],char*env[]*/)
//{
//    char * env = getenv("HELLO");
//    if(env){
//        printf("%s\n", env);
//    }
////  char*path = getenv("PATH");
////  if(path==NULL) return 1;
////  printf("path:%s\n",path);
////  for(int i=0;env[i];i++)
////  {
////    printf("env[%d]->%s\n", i, env[i]);
////  }
////  fork();
//
////  if(argc!=2)
////  {
////    printf("usage:%s - [a,b,c,d]\n",argv[0]);
////    return 1;
////  }
////  if(strcmp(argv[1],"-a")==0)
////  {
////    printf("this is function1\n");
////  }
////  else if(strcmp(argv[1],"-b")==0)
////  {
////    printf("this is function2\n");
////  }
////  else if(strcmp(argv[1],"-c")==0)
////  {
////    printf("this is function3\n");
////  }
////  else if(strcmp(argv[1],"-d")==0)
////  {
////    printf("this is function4\n");
////  }
////  else
////  {
////    printf("this is no function!!!\n");
////  }
//  return 0;
//}
